package com.ruoyi.ycl.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ycl.domain.vo.BsClVo;
import com.ruoyi.ycl.domain.bo.BsClBo;
import com.ruoyi.ycl.service.IBsClService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 材料
 *
 * @author zyb
 * @date 2024-03-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ycl/bsCl")
public class BsClController extends BaseController {

    private final IBsClService iBsClService;

    /**
     * 查询材料列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<BsClVo> list(BsClBo bo, PageQuery pageQuery) {
        return iBsClService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出材料列表
     */
    @SaCheckLogin
    @Log(title = "材料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BsClBo bo, HttpServletResponse response) {
        List<BsClVo> list = iBsClService.queryList(bo);
        ExcelUtil.exportExcel(list, "材料", BsClVo.class, response);
    }

    /**
     * 获取材料详细信息
     *
     * @param clId 主键
     */
    @SaCheckLogin
    @GetMapping("/{clId}")
    public R<BsClVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long clId) {
        return R.ok(iBsClService.queryById(clId));
    }

    /**
     * 新增材料
     */
    @SaCheckLogin
    @Log(title = "材料", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BsClBo bo) {
        return toAjax(iBsClService.insertByBo(bo));
    }

    /**
     * 修改材料
     */
    @SaCheckLogin
    @Log(title = "材料", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BsClBo bo) {
        return toAjax(iBsClService.updateByBo(bo));
    }

    /**
     * 删除材料
     *
     * @param clIds 主键串
     */
    @SaCheckLogin
    @Log(title = "材料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{clIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] clIds) {
        return toAjax(iBsClService.deleteWithValidByIds(Arrays.asList(clIds), true));
    }
}
